﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SharpKml.Dom;
using SharpKml.Dom.GX;

namespace ConsoleApplication11
{
    class Program
    {
        static void Main(string[] args)
        {
            var parser = new SharpKml.Base.Parser();

            var s = File.ReadAllText(@"C:\Users\admin pc\Desktop\doc.kml");

            parser.ParseString(s, true);

            var kml = (Kml)parser.Root;

            var doc = (Document)kml.Feature;

            foreach (var feature in doc.Features)
            {
                Debug.Print(feature.Name);
                // Debug.Print(feature.Name);

                var placemark = (Placemark)feature;

                if (feature.Id == "tour")
                {
                    var multiTracks = (MultipleTrack)placemark.Geometry;

                    var tracks = multiTracks.Tracks;

                    foreach (var track in tracks)
                    {
                        var coordinates = track.Coordinates;

                        var when = track.When;

                       var trackData = coordinates.Zip(when, (vector, s1) => new Tuple<string, double, double, double?>(s1, vector.Longitude, vector.Latitude,
                            vector.Altitude));

                        foreach (var stopPoint in trackData)
                        {
                            Console.WriteLine("{0} - {1}, {2}, {3}", stopPoint.Item1, stopPoint.Item2, stopPoint.Item3, stopPoint.Item4);
                        }


//                        var data = track.ExtendedData.SchemaData;
//
//                        foreach (var schemaData in data)
//                        {
//                            var arrayList = schemaData.GXSimpleArray;
//
//                            foreach (var simpleArrayData in arrayList)
//                            {
//                                Debug.Print(simpleArrayData.Name);
//
//                                foreach (var value in simpleArrayData.Values)
//                                {
//                                    Console.Write(value);
//                                }
//                            }
//                        }
                    }
                }
            }

        }
    }
}
